#ifndef DATABASE_H
#define DATABASE_H

#define SIZE_IP 16
#define SIZE_PORT 6
#define SIZE_STR_FIELD 50

#include <pthread.h>
#include "network.h"

struct database *db;
pthread_mutex_t m_db;

struct database {
	struct peer **list_peer;
	int nb_peer;
};

struct peer {
	char *ip;
	char *port;
	struct file **list_file;
	int nb_file;
};

struct file {
	char *name;
	char *size;
	char *block_size;
	char *key;
	int is_seed;
};

struct database *create_database ();
struct peer * init_peer ();

struct peer * create_peer ();
struct file * create_file ();

struct peer * find_peer (struct peer *p_search);
struct peer * find_peer_with_ip (struct ip_and_socket i_and_s);
struct file * find_file (char * key);

void add_file_to_peer (struct file *f, struct peer *p);
void add_peer_to_database (struct peer *p);

void delete_peer_from_database (struct peer *p);

void print_database ();

#endif
